extends InteractiveObject3D

class_name SlidingDoor3D

enum State {OPEN, CLOSED}

@export var extended_position_point: Node3D
@export var movement_speed = 1

@export var state = State.CLOSED

var closed_position: Vector3
var open_position: Vector3

# Called when the node enters the scene tree for the first time.

func _ready() -> void:
	closed_position = position
	if extended_position_point != null:
		open_position = position + extended_position_point.position
	else:
		open_position = closed_position

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if state == State.OPEN:
		if position != open_position:
			position+= (open_position - closed_position).normalized() * movement_speed * delta
	else:
		position+= (closed_position - open_position).normalized() * movement_speed * delta
	position = position.clamp(
		closed_position.min(open_position),
		closed_position.max(open_position)
	)

func interact(params: Dictionary = {}) -> void:
	state = State.OPEN if state == State.CLOSED else State.CLOSED
